﻿<Window x:Class="DSSDataServiceGenerator.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DSSDataServiceGenerator"
        xmlns:local.Controls="clr-namespace:DSSDataServiceGenerator.Controls"
        xmlns:local.ViewModel="clr-namespace:DSSDataServiceGenerator.ViewModel"
        Title="WSO2 Data Service Server Code Generator for CS.NET"
        MinHeight="350"
        MinWidth="525"
        WindowState="Maximized"
        Loaded="Window_Loaded"
        RenderOptions.BitmapScalingMode="NearestNeighbor">
    <Window.DataContext>
        <local.ViewModel:MetadataViewModel />
    </Window.DataContext>
    <Window.Resources>
        <Style TargetType="{x:Type local.Controls:CodeEditor}">
            <Setter Property="TextBlock.FontFamily"
                    Value="Courier New" />
            <Setter Property="TextBlock.FontSize"
                    Value="12" />
            <Setter Property="TextBox.IsReadOnly"
                    Value="True" />
        </Style>
        <Style TargetType="DataGrid">
            <Setter Property="GridLinesVisibility"
                    Value="None" />
            <Setter Property="AutoGenerateColumns"
                    Value="False" />
            <Setter Property="SelectionMode"
                    Value="Single" />
            <Setter Property="SelectionUnit"
                    Value="FullRow" />
            <Setter Property="HeadersVisibility"
                    Value="Column" />
            <Setter Property="CanUserReorderColumns"
                    Value="False" />
            <Setter Property="CanUserAddRows"
                    Value="False" />
            <Setter Property="CanUserDeleteRows"
                    Value="False" />
            <Setter Property="CanUserResizeColumns"
                    Value="True" />
            <Setter Property="CanUserResizeRows"
                    Value="False" />
        </Style>
        <DataTemplate x:Key="ModelDesignerItem_DataTemplate">
            <Border MaxWidth="150"
                    MinWidth="150"
                    MaxHeight="250"
                    BorderBrush="Gray"
                    BorderThickness="1"
                    CornerRadius="6"
                    Padding="3">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Border Padding="3"
                            IsHitTestVisible="False">
                        <Border.ToolTip>
                            <MultiBinding StringFormat="{}[{0}].[{1}]">
                                <MultiBinding.Bindings>
                                    <Binding Path="Attribute[Namespace].Value" />
                                    <Binding Path="Attribute[Name].Value" />
                                </MultiBinding.Bindings>
                            </MultiBinding>
                        </Border.ToolTip>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Image Source="Resources/Table_16x16.png"
                                   Stretch="None"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center" />
                            <TextBlock Name="Title_TextBlock"
                                       Grid.Column="1"
                                       Margin="3"
                                       ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}"
                                       TextTrimming="CharacterEllipsis">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}[{0}].[{1}]">
                                        <MultiBinding.Bindings>
                                            <Binding Path="Attribute[Namespace].Value" />
                                            <Binding Path="Attribute[Name].Value" />
                                        </MultiBinding.Bindings>
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </Grid>
                    </Border>
                    <Border Grid.Row="1"
                            Grid.ColumnSpan="2"
                            BorderBrush="Gray"
                            BorderThickness="1"
                            CornerRadius="0,0,6,6"
                            Padding="4"
                            Background="WhiteSmoke">
                        <ScrollViewer VerticalScrollBarVisibility="Auto"
                                      HorizontalScrollBarVisibility="Disabled">
                            <ItemsControl ItemsSource="{Binding Elements[Property]}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>
                                            <Image Source="Resources/Column_16x16.png"
                                                   Stretch="None"
                                                   Name="Icon_Image" />
                                            <TextBlock Grid.Column="1"
                                                       Padding="3"
                                                       Name="Title_TextBlock"
                                                       ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}">
                                                <TextBlock.Text>
                                                    <MultiBinding StringFormat="{}{0}) {1} ({2})">
                                                        <MultiBinding.Bindings>
                                                            <Binding Path="Attribute[OrdinalPosition].Value" />
                                                            <Binding Path="Attribute[Name].Value" />
                                                            <Binding Path="Attribute[DataType].Value" />
                                                        </MultiBinding.Bindings>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </Grid>
                                        <DataTemplate.Triggers>
                                            <DataTrigger Binding="{Binding Attribute[IsPrimaryKey].Value}"
                                                         Value="1">
                                                <Setter Property="Source"
                                                        Value="Resources/PrimaryKey_16x16.png"
                                                        TargetName="Icon_Image" />
                                            </DataTrigger>
                                        </DataTemplate.Triggers>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                    </Border>
                </Grid>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <Window.InputBindings>
        <KeyBinding Key="F5"
                    Command="{Binding ConnectCommand}" />
    </Window.InputBindings>
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Header="_Connect..."
                          Command="{Binding ConnectCommand}" />
                <Separator />
                <!--<MenuItem Header="Save _WSDL As..."
                          Command="{Binding SaveAsCommand}" />
                <MenuItem Header="Save _Proxy Classes As..."
                          Command="{Binding SaveAsCommand}" />
                <MenuItem Header="Save _DataService As..."
                          Command="{Binding SaveAsCommand}"
                          CommandParameter="{Binding Text, ElementName=DataServiceDefinition_TextBox}" />
                <MenuItem Header="Save _View Model As..."
                          Command="{Binding SaveAsCommand}" />
                <Separator />-->
                <MenuItem Header="Generate"
                          Command="{Binding GenerateCommand}" />
                <MenuItem Header="Publish"
                          Command="{Binding PublishCommand}" />
                <Separator />
                <MenuItem Header="E_xit"
                          Command="{Binding ExitCommand}" />
            </MenuItem>
            <!--<MenuItem Header="_Tools">
                <MenuItem Header="_Generate WSDL..."
                          Command="{Binding GenerateWsdlCommand}" />
                <MenuItem Header="_Generate Proxy Classes..."
                          Command="{Binding GenerateCsharpCommand}" />
                <MenuItem Header="_Generate Data Services..."
                          Command="{Binding GenerateDataServiceCommand}" />
                <MenuItem Header="_Generate View Model..."
                          Command="{Binding GenerateViewModelCommand}" />
            </MenuItem>-->
            <MenuItem Header="_Help">
                <MenuItem Header="_About"
                          Name="AboutMenuItem"
                          Click="AboutMenuItem_Click" />
            </MenuItem>
        </Menu>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto"
                               MinHeight="5" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Border Padding="3"
                        BorderThickness="0,0,0,1"
                        BorderBrush="Black">
                    <StackPanel Orientation="Vertical">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Text="Group Name:"
                                       VerticalAlignment="Center"
                                       Padding="4" />
                            <TextBox Grid.Column="1"
                                     Text="{Binding Metadata.Attribute[Name].Value}" />
                            <TextBlock Text="Namespace:"
                                       VerticalAlignment="Center"
                                       Padding="4"
                                       Grid.Row="1" />
                            <TextBox Grid.Column="1"
                                     Grid.Row="1"
                                     Text="{Binding Metadata.Attribute[Namespace].Value}" />
                        </Grid>
                    </StackPanel>
                </Border>
                <local.Controls:ModelDesigner Grid.Row="1"
                                              ItemsSource="{Binding Metadata.Elements}"
                                              ItemTemplate="{StaticResource ModelDesignerItem_DataTemplate}" />
            </Grid>
            <GridSplitter HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          ResizeDirection="Rows"
                          Background="WhiteSmoke"
                          ResizeBehavior="PreviousAndNext"
                          Grid.Row="1" />
            <Grid Grid.Row="2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="250" />
                    <ColumnDefinition Width="Auto"
                                      MinWidth="5" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <ListView ItemsSource="{Binding PublishOutput}"
                          Background="Transparent"
                          BorderThickness="0"
                          Name="PublishOutput_TreeView">
                    <ListView.ItemTemplate>
                        <HierarchicalDataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <CheckBox IsChecked="{Binding IsSelectedToBePublished}"
                                          VerticalAlignment="Center"
                                          HorizontalAlignment="Center" />
                                <TextBlock  Grid.Column="1"
                                            Padding="3"
                                            ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}">
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0} ({1})">
                                            <MultiBinding.Bindings>
                                                <Binding Path="Name" />
                                                <Binding Path="Directory" />
                                            </MultiBinding.Bindings>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </Grid>
                        </HierarchicalDataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <GridSplitter HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch"
                              ResizeDirection="Columns"
                              Background="WhiteSmoke"
                              ResizeBehavior="PreviousAndNext"
                              Grid.Column="1" />
                <local.Controls:CodeEditor Text="{Binding SelectedItem.Content, ElementName=PublishOutput_TreeView}"
                                           CodeLanguage="{Binding SelectedItem.Language, ElementName=PublishOutput_TreeView}"
                                           Grid.Column="2" />
            </Grid>
        </Grid>
    </DockPanel>
</Window>